package com.xxx.clickhousedemo.service;

import com.alibaba.fastjson.JSONObject;
import com.xxx.clickhousedemo.mapper.ClickUserMapper;
import com.xxx.clickhousedemo.pojo.bean.ResponseDTO;
import com.xxx.clickhousedemo.pojo.entity.ClickUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ChickHouserService {

    private static final Logger logger = LoggerFactory.getLogger(ChickHouserService.class);

    @Resource
    private ClickUserMapper clickUserMapper;

    public List<ClickUser> getList() {
        logger.info("进入操作");
        try {
            List<ClickUser> list= clickUserMapper.queryUser();
            logger.info("clickhouse查询结果为：{}", JSONObject.toJSON(list));
            return list;
        } catch (Exception e) {
            logger.error("操作异常，{}", e.getMessage(), e);
        }
        return null;
    }

    public List<ClickUser> insert(ClickUser clickUser) {
        logger.info("进入操作");
        try {
            logger.info("===========先查询============");
            List<ClickUser> list= clickUserMapper.queryUser();
            logger.info("clickhouse查询结果为：{}", JSONObject.toJSON(list));
            logger.info("===========在新增============");
            clickUserMapper.insertUser(clickUser);
            logger.info("===========再次查询============");
            List<ClickUser> rlist= clickUserMapper.queryUser();
            logger.info("clickhouse查询结果为：{}", JSONObject.toJSON(rlist));
            return rlist;
        } catch (Exception e) {
            logger.error("操作异常，{}", e.getMessage(), e);
        }
        return null;
    }

}
